//https://blog.csdn.net/zl1zl2zl3/article/details/81357146
import { PureComponent } from 'react';
import {
    Row,
    Col,
    Form,
    Input,
    Modal,
} from 'antd';

const FormItem = Form.Item;



// 修改表单
@Form.create()
class UpdateForm extends PureComponent {
    static defaultProps = {
        handleUpdate: () => {},
    handleUpdateModalVisible: () => {},
values: {},
};

constructor(props) {
    super(props);

    this.state = {
        formVals: {
                id: props.values.id,
                article_id: props.values.article_id,
                images_client: props.values.images_client,
                images_type: props.values.images_type,
                type_store: props.values.type_store,
                goods_commonid: props.values.goods_commonid,
                color_id: props.values.color_id,
                goods_image: props.values.goods_image,
                goods_image_samll: props.values.goods_image_samll,
                goods_image_sort: props.values.goods_image_sort,
                is_default: props.values.is_default,
        },
    };


}

 handleLocalUpdate = () => {
    const { form, handleUpdate } = this.props;
    const { formVals: oldValue } = this.state;
    form.validateFields((err, fieldsValue) => {
      if (err) return;
      const formVals = { ...oldValue, ...fieldsValue };
      this.setState(
        {
          formVals,
        }
      );
     
     handleUpdate(formVals);

    });
  };


renderContent = (formVals) => {
    const { form } = this.props;

    return (
        <Form  layout="vertical" hideRequiredMark>


            <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

                    <Col  md={12} sm={24}>
	                    <FormItem  label="公共内容id">
	                        {form.getFieldDecorator('goods_commonid', {
	                        rules: [{ required: false, message: '请输入至少五个字符的公共内容id！', min: 5 }],
	                        initialValue: formVals.goods_commonid,
	                        })(<Input placeholder="请输入" />)}
	                    </FormItem>
                    </Col>
					
                    <Col  md={12} sm={24}>
	                    <FormItem  label="图片原图">
	                        {form.getFieldDecorator('goods_image', {
	                        rules: [{ required: false, message: '请输入至少五个字符的图片原图！', min: 5 }],
	                        initialValue: formVals.goods_image,
	                        })(<Input placeholder="请输入" />)}
	                    </FormItem>
                    </Col>


            </Row>




    </Form>
);

};



render() {
    const { updateModalVisible, handleUpdateModalVisible, values} = this.props;
    const {  formVals } = this.state;

    return (
        <Modal
    width={800}
    height={800}
    bodyStyle={{ padding: '32px 40px 48px' }}
    destroyOnClose
    title="修改"
    visible={updateModalVisible}
    onOk={() => this.handleLocalUpdate()}
    onCancel={() => handleUpdateModalVisible(false, values)}
    afterClose={() => handleUpdateModalVisible()}
>

    {this.renderContent(formVals)}
</Modal>
);
}

}

export default UpdateForm;




